<!--
 * @Description: 
 * @Author: ljy
 * @Date: 2021-12-08 19:16:23
 * @LastEditors: ljy
 * @LastEditTime: 2021-12-13 22:11:30
-->
<template>
  <div class="user">
    <div class="inS">
      <div>
        <el-input clearable v-model="from.username" placeholder="请输入用户名"></el-input>
      </div>
      <div>
        <el-input v-model="from.mobile" placeholder="请输入手机号"></el-input>
      </div>
      <div>
        <el-button @click="toSearch" type="primary" style="line-height: 6px"
          ><i class="el-icon-search"></i>查找</el-button
        >
        <el-button type="warning" style="line-height: 6px" @click="exp()"
          ><i class="el-icon-download"></i>导出</el-button
        >
      </div>
    </div>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="id" label="用户ID" width="100"> </el-table-column>
      <el-table-column prop="username" label="用户名" width="180">
      </el-table-column>
      <el-table-column prop="mobile" label="手机号码"> </el-table-column>
      <el-table-column label="性别">
        <template slot-scope="scope">
          <div v-if="scope.row.gender == 1">男</div>
          <div v-if="scope.row.gender == 2">女</div>
          <div v-if="scope.row.gender == 0">未知</div>
        </template>
      </el-table-column>
      <el-table-column label="生日" width="180">
        <template slot-scope="scope">
          <div>
            {{scope.row.birthday?moment(scope.row.birthday).format("YYYY-MM-DD"):""}}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="用户等级">
        <template slot-scope="scope">
          <div v-if="scope.row.user_level == 1">VIP用户</div>
          <div v-if="scope.row.user_level == 2">区域代理用户</div>
          <div v-if="scope.row.user_level == 0">普通用户</div>
        </template>
      </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <div v-if="scope.row.status == 1">禁用</div>
          <div v-if="scope.row.status == 2">注销</div>
          <div v-if="scope.row.status == 0">可用</div>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        label="上次登录时间"
        width="180"
      >
      <template slot-scope="scope">
          <div>
            {{scope.row.last_login_time?moment(scope.row.last_login_time).format("YYYY-MM-DD HH:mm:ss"):""}}
          </div>
        </template>
      </el-table-column>
    </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="params.pageNum"
        :page-sizes="[5, 8, 10, 20]"
        :page-size="params.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
  </div>
</template>

<script>
import axios from "axios";
import moment from "moment";
export default {
  data() {
    return {
      moment,
      tableData: [],
      input: "",
      from:{
        username:"",
        mobile:""
      },
      params:{
        pageNum:1,
        pageSize:10
      },
      total:0
    };
  },
  computed: {},
  watch:{
    params:{
      handler(){
        this.init()
      },
      deep:true
    }
  },
  methods: {
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.params.pageSize  = val
      this.params.pageNum  = 1
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.params.pageNum  = val
    },
    exp() {
      alert("1111");
    },
    toSearch(){
      this.params.pageNum =1
      this.init()
    },
    init() {

      let temp = {
        ...this.params,
        ...this.from
      }
      // for(let i in temp){
      //   console.log(i);
      // }
      console.log(temp);
      axios({
        method: "get",
        url: "http://localhost:3000/users/pageQuery",
        params: temp,
      }).then((res) => {
        console.log(res);
        this.tableData = res.data.data;
        this.total = res.data.total
      });
    },
  },
  created() {
    this.init();
  },
  mounted() {},
};
</script>
<style lang="scss" scoped>
.user {
  margin: 20px;
}
.inS {
  display: flex;
  margin: 20px 0;
}
::v-deep .inS .el-input__inner {
  margin-right: 10px;
  width: 200px;
  height: 30px;
}
.el-icon-search,
.el-icon-download {
  margin-right: 5px;
}
</style>